package com.basker.pisces.springcloud.utils;

import org.springframework.util.Assert;

import com.basker.pisces.common.enums.SignatureAlgorithmType;
import com.basker.pisces.common.sign.SignGenerator;
import com.basker.pisces.springcloud.signature.Signature;

/**
 * 签名工具类，该签名规则仅适用于公司内容接口
 *
 * @author hangwen
 */
public class SignatureUtils {

    /**
     * 根据服务接口的请求参数生成签名,参数之间会有"="和"&"分隔
     *
     * @param signType
     * @param appId
     * @param timestamp
     * @param argument
     * @return
     */
    public static Signature generateSignature(SignatureAlgorithmType signType, String appId, long timestamp,
                                              Object argument) {
        Assert.hasText(appId, "parameter 'appId' is required");

        SignGenerator signGenerator = new SignGenerator(signType, appId, timestamp, argument);

        String sign = signGenerator.generate();
        return new Signature(sign, appId, timestamp);
    }

}
